﻿var AMing_Module_AjaxHtml = new function () { };
AMing_Module_AjaxHtml = {
    head_img_index: 0,
    GetHtmlData: function (key) {
        $.ajax({
            url: "/main/ajaxhtml",
            data: { key: key },
            success: function (data, status) {
                AMing_Module_AjaxHtml.ChangeHeadImage(data);
            }
        });
    },
    ChangeHeadImage: function (data) {
        var $head_bg_img = $(".content_frame_head_bg,.content_frame_head_avatar_img");
        var $head_title = $(".content_frame_head_title");
        var $avatar = $(".content_frame_head_avatar");
        var $avatar_title = $(".content_frame_head_avatar_title");
        var $avatar_img = $(".content_frame_head_avatar_img");
        var $main_content_ajax = $(".main_content_ajax");



        var img_left = (data.HeadImageLeft + 5) * -1;

        $head_bg_img.animate({ opacity: 0 }, 400, function () {
            $head_bg_img.css("background-image", "url(" + data.HeadImage + ")");
            $avatar_img.css({ "background-position-x": img_left + "px" }, 800);
            $head_bg_img.animate({ opacity: 1 }, 400);

            $head_title.css("color", data.HeadTitleColor);
            $avatar_title.css("color", data.AvatarTitleColor);
            $head_title.html(data.HeadTitle);
            $avatar_title.html(data.AvatarTitle);

            $main_content_ajax.html(data.Html);
        });

        $main_content_ajax.animate({ opacity: 0 }, 400, function () {
            $main_content_ajax.animate({ opacity: 1 }, 400);
            $main_content_ajax.html(data.Html);
            AMing_Module_AjaxHtml.Init_Link();
        });

        $avatar.animate({ left: data.HeadImageLeft }, 800);
        $head_title.animate({ left: data.HeadTitleLeft }, 800);
        //$avatar_img.animate({ backgroundPositionX: img_left }, 800);
    },
    Init_Link: function () {
        $("a").each(function (a, b, c) {
            var isjump = $(this).attr("isjump");
            var pagekey = $(this).attr("pagekey");
            if (isjump) {
                if (!pagekey) {
                    pagekey = $(this).attr("href");
                    $(this).attr("pagekey", pagekey);
                }
                $(this).attr("href", "javascript:void(0);");
            }
        });
        $("a").click(function () {
            var $this = $(this);
            var pagekey = $this.attr("pagekey");
            var isjump = $this.attr("isjump");
            if (isjump) {
                if (pagekey) {
                    AMing_Module_AjaxHtml.GetHtmlData(pagekey);
                }
            }
        });
    }

};
$(document).ready(function () {
    AMing_Module_AjaxHtml.Init_Link();
});